ASM    = nasm
CC     = gcc
LD     = ld

AFLAGS = -f aout
CFLAGS = -Wall -O -fstrength-reduce -fomit-frame-pointer -finline-functions -nostdinc -fno-builtin -I./include
LFLAGS = -Map $(MAPFILE) -Tarch/x86/init/link.ld

MAPFILE = arch/x86/bin/kernel.map

OBJS  = arch/x86/init/init.o arch/x86/init/interrupt.o arch/x86/init/GDT.o arch/x86/init/IDT.o arch/x86/init/ISR.o arch/x86/init/PIC.o video/VGA.o
OBJS += arch/x86/init/IRQ.o arch/x86/init/PIT.o lib/string.o lib/asmutils.o memory/kheap.o main.o
#OBJS = $(patsubst %.c,%.o,$(wildcard *.c))
#OBJS += $(patsubst %.s,%.o,$(wildcard *.s))

KERNEL = arch/x86/bin/kernel.bin

all: $(KERNEL)

$(KERNEL): $(OBJS)
	@echo "Linking "$@
	$(LD) $(OBJS) $(LFLAGS) -o $(KERNEL)
	@echo "*********************************"
	@echo "*                               *"
	@echo "*           SUCCESS             *"
	@echo "*                               *"
	@echo "*    Kernel is ready to use.    *"
	@echo "*                               *"
	@echo "*********************************"
	
%.o: %.S
	@echo "Asembling "$@
	$(ASM) $(AFLAGS) $<

%.o: %.c
	@echo "Compiling "$@
	$(CC) $(CFLAGS) -c $< -o $@
	

clean:
	-rm -f $(KERNEL) $(OBJS) $(MAPFILE)
